package com.aaa.shuke2024.controller;

import com.aaa.shuke2024.entity.AlarmLimit;
import com.aaa.shuke2024.entity.User;
import com.aaa.shuke2024.service.AlarmLimitService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 告警管理表(AlarmLimit)表控制层
 *
 * @author teacherChen
 * @since 2024-12-04 16:10:59
 */
@RestController
@RequestMapping("alarmLimit")
public class AlarmLimitController {
    /**
     * 服务对象
     */
    @Resource
    private AlarmLimitService alarmLimitService;

    /**
     * 分页查询
     *
     * @param alarmLimit 筛选条件
     * @param page      分页对象
     * @param limit      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<AlarmLimit>> queryByPage(AlarmLimit alarmLimit,  int page, int limit) {
        PageRequest pageRequest = PageRequest.of(page-1, limit);
        return ResponseEntity.ok(this.alarmLimitService.queryByPage(alarmLimit, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<AlarmLimit> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.alarmLimitService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param alarmLimit 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<AlarmLimit> add(AlarmLimit alarmLimit) {
        alarmLimit.setCreateTime(new Date());
        return ResponseEntity.ok(this.alarmLimitService.insert(alarmLimit));
    }

    /**
     * 编辑数据
     *
     * @param alarmLimit 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<AlarmLimit> edit(AlarmLimit alarmLimit) {
        alarmLimit.setCreateTime(new Date());
        return ResponseEntity.ok(this.alarmLimitService.update(alarmLimit));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.alarmLimitService.deleteById(id));
    }

}

